$(document).ready(function(){
    //详情说明
	initMySummernote("secureDetail");	
	loadData();
});

//显示数据(修改)
function loadData(){
	    $.ajax({  
        type : "GET",  
        url : urlcore + "/api/insurance/insuranceDetails", //图片上传出来的url，返回的是图片上传后的路径，http格式  
        dataType : "json",
        headers:{"Content-Type":"application/json;charset=UTF-8"},
        data : {},
        async: false,
        success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
        	var da=data.data[0];
        	if(data.success==true){
        		if(da!=null){
        			$('#id').val(da.id);
        			$("#title").val(da.title);
        			$("#phone").val(da.phone);
            		$('#secureDetail').summernote('code',da.content);
        		}
        	}else {
                alert(data.msg);
            }
        },
        error:function(){  
            alert("失败");  
        }  
    }); 
}











//表达提交
function onSave(){
	var id=$("#id").val();
	var title=$("#title").val();
	var phone=$("#phone").val();
	var secureDetail=$('#secureDetail').summernote('code');	
	$.ajax({  
	    type : "POST",  
	    url : urlcore + "/api/insurance/addOrUpdateInsurance",
	    headers:{"Content-Type":"application/json;charset=UTF-8"},	    
	    data :  JSON.stringify({
	    			id:id,
	    			title:title,
	    			phone:phone,
		        	content:secureDetail      		
	    	}),
	    async: false,
	    success: function(data) {//data是返回的hash,key之类的值，key是定义的文件名 
	    	if(data.success==true){
				$('#id').val(data.data.id);
				alert("修改成功");
				location.reload();
	    	}else if (data.code == 'OVERTIME') {
	            var thisUrl = window.location.href;
	            if (thisUrl.indexOf('login.html') <= -1) {
	                top.window.location.href = "login.html";
	            }
	        } else {
	            alert(data.msg);
	        }
	    },
	    error:function(){  
	        alert("上传失败");  
	    }  
	}); 
	

}
